#include <cstdint>
#include <chrono>
#include <mutex>

class game_id_generator {
public:
    game_id_generator(const game_id_generator &) = delete;
    game_id_generator &operator=(const game_id_generator &) = delete;

    static game_id_generator &get_instance() {
        static game_id_generator instance_;
        return instance_;
    }

    void set_server_id(uint16_t server_id) {
        server_id_ = server_id;
    }

    uint16_t server_id() const {
        return server_id_;
    }

    uint64_t generate();

private:
    game_id_generator() = default;
    uint16_t server_id_ = 0;
    uint16_t sequence_ = 0;
    uint64_t last_timestamp_ = 0;
    std::mutex mutex_;
};
